import React from "react";

import { Redirect, Route, Switch, HashRouter } from "react-router-dom";
import { getToken } from "utils/auth";

import Layout from "layout";
import Login from "pages/login";
import NotFound from "pages/404";
import NotAuth from "pages/403";

const Router = () => {
  return (
    <HashRouter>
      <Switch>
        <Route exact path={"/login"} component={Login} />
        <Redirect exact from={"/"} to={"/login"} />
        <Route
          path={"/layout"}
          render={() =>
            !getToken() ? <Layout name={"/layout"} /> : <Redirect to={"/403"} />
          }
        />

        <Route
          path={"/test"}
          render={() =>
            getToken() ? <Layout name={"/test"} /> : <Redirect to={"/403"} />
          }
        />
        <Route path="/403" component={NotAuth} />
        <Route path={"*"} component={NotFound} />
      </Switch>
    </HashRouter>
  );
};

export default Router;
